package icu.makka.yygh.order.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import icu.makka.yygh.enums.OrderStatusEnum;
import icu.makka.yygh.model.order.OrderInfo;
import icu.makka.yygh.order.service.impl.OrderInfoServiceImpl;
import icu.makka.yygh.result.Result;
import icu.makka.yygh.vo.order.OrderCountQueryVo;
import icu.makka.yygh.vo.order.OrderQueryVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/admin/order/orderInfo")
public class OrderController {

    @Autowired
    private OrderInfoServiceImpl orderInfoService;

    /**
     * 获取分页列表
     * @param page
     * @param limit
     * @param orderQueryVo
     * @return
     */
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page, @PathVariable Long limit, OrderQueryVo orderQueryVo) {
        log.info("获取分页列表，page={}，limit={}，orderQueryVo={}", page, limit, orderQueryVo);
        Page<OrderInfo> pageParam = new Page<>(page, limit);
        IPage<OrderInfo> pageModel = orderInfoService.selectPage(pageParam, orderQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * 获取订单状态
     * @return
     */
    @GetMapping("getStatusList")
    public Result getStatusList() {
        log.info("获取订单状态...");
        return Result.ok(OrderStatusEnum.getStatusList());
    }

    /**
     * 根据id获取订单详情
     * @param id
     * @return
     */
    @GetMapping("/show/{id}")
    public Result getById(@PathVariable("id") Long id) {
        log.info("根据id获取订单详情，id={}", id);
        Map<String, Object> map = orderInfoService.show(id);
        return Result.ok(map);
    }

    /**
     * 获取订单统计数据
     * @param orderCountQueryVo
     * @return
     */
    @PostMapping("inner/getCountMap")
    public Map<String, Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo) {
        log.info("获取订单统计数据，orderCountQueryVo={}", orderCountQueryVo);
        Map<String, Object> map = orderInfoService.getCountMap(orderCountQueryVo);
        return map;
    }
}
